package com.cuiyun97.controller.admin;

import com.cuiyun97.result.Result;
import com.cuiyun97.utils.AliSmsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api(tags = "测试接口")
@RequestMapping("/admin/test")
public class TestController {

    /**
     * 注册短信发送类
     *
     * 如果此类含有DI注入, 不能实例化, 只能注入操作
     */
    @Resource
    private AliSmsUtil aliSmsUtil;

    /**
     * 简单测试
     *
     * @return
     */
    @GetMapping
    @ApiOperation("简单测试")
    public Result test() {
        return Result.success("这是一个简单测试");
    }

    /**
     * 全局异常测试
     *
     * @return
     */
    @GetMapping("/exception")
    @ApiOperation("异常测试")
    public Result exception() {

        int i = 1 / 0;

        return Result.success();
    }

    /**
     * 短信测试
     *
     * @param mobile
     * @param code
     * @return
     * @throws Exception
     */
    @PostMapping("/sms")
    @ApiOperation("短信发送")
    public Result sms(String mobile, String code) throws Exception {

        // aliSmsUtil.send("18620885097", "136258");
        aliSmsUtil.send(mobile, code);

        return Result.success("成功发送,验证码是: " + code);
    }
}
